home *** CD-ROM | disk | FTP | other *** search
/ Aminet 35 / Aminet 35 (2000)(Schatztruhe)[!][Feb 2000].iso / Aminet / gfx / misc / gnuplot-src.lha / gnuplot-3.7.1src / gnuplot-3.7.1.lha / gnuplot-3.7.1 / os2 / gnupmdrv.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-10-04  |  8.9 KB  |  299 lines

  1. #ifdef INCRCš{QµŸîr RCSid[]="$Id: gnupmdrv.c,v 1.2 1998/10/03 20:14:29 lhecking Exp $" ;
  2. #endif
  3.  
  4. /****************************************************************************
  5.  
  6.     PROGRAM: gnupmdrv
  7.     
  8.     Outboard PM driver for GNUPLOT 3.3
  9.  
  10.     MODULE:  gnupmdrv.c
  11.         
  12.     This file contains the startup procedures for gnupmdrv
  13.        
  14. ****************************************************************************/
  15.  
  16. /* PM driver for GNUPLOT */
  17.  
  18. /*[
  19.  * Copyright 1992, 1993, 1998   Roger Fearick
  20.  *
  21.  * Permission to use, copy, and distribute this software and its
  22.  * documentation for any purpose with or without fee is hereby granted,
  23.  * provided that the above copyright notice appear in all copies and
  24.  * that both that copyright notice and this permission notice appear
  25.  * in supporting documentation.
  26.  *
  27.  * Permission to modify the software is granted, but not the right to
  28.  * distribute the complete modified source code.  Modifications are to
  29.  * be distributed as patches to the released version.  Permission to
  30.  * distribute binaries produced by compiling modified sources is granted,
  31.  * provided you
  32.  *   1. distribute the corresponding source modifications from the
  33.  *    released version in the form of a patch file along with the binaries,
  34.  *   2. add special version identification to distinguish your version
  35.  *    in addition to the base release version number,
  36.  *   3. provide your name and address as the primary contact for the
  37.  *    support of your modified version, and
  38.  *   4. retain our contact information in regard to use of the base
  39.  *    software.
  40.  * Permission to distribute the released version of the source code along
  41.  * with corresponding source modifications in the form of a patch file is
  42.  * granted with same provisions 2 through 4 for binary distributions.
  43.  *
  44.  * This software is provided "as is" without express or implied warranty
  45.  * to the extent permitted by applicable law.
  46. ]*/
  47.  
  48.  
  49. /*
  50.  * AUTHOR
  51.  * 
  52.  *   Gnuplot driver for OS/2:  Roger Fearick
  53.  * 
  54.  * Send your comments or suggestions to 
  55.  *  info-gnuplot@dartmouth.edu.
  56.  * This is a mailing list; to join it send a note to 
  57.  *  majordomo@dartmouth.edu.  
  58.  * Send bug reports to
  59.  *  bug-gnuplot@dartmouth.edu.
  60. **/
  61.  
  62. #define INCL_PM
  63. #define INCL_WIN
  64. #define INCL_SPL
  65. #define INCL_SPLDOSPRINT
  66. #define INCL_DOSMEMMGR
  67. #define INCL_DOSPROCESS
  68. #define INCL_DOSFILEMGR
  69. #include <os2.h>
  70. #include <string.h>
  71. #include <stdio.h>
  72. #include <stdlib.h>
  73. #include "gnupmdrv.h"
  74.  
  75. /*==== g l o b a l    d a t a ================================================*/
  76.  
  77. char szIPCName[256] ;
  78. char szIniFile[256] ;
  79. #define IPCDEFAULT "gnuplot"
  80. int  bServer=0 ;
  81. int  bPersist=0 ;
  82. int  bWideLines=0 ;
  83. int  bEnhanced=0 ;
  84.  
  85. /*==== l o c a l    d a t a ==================================================*/
  86.  
  87.             /* class names for window registration */
  88.  
  89. static char szChildName []     = "Gnuchild" ;
  90.  
  91. static char szTitle[256] = "Gnuplot" ;
  92.  
  93. /*==== f u n c t i o n s =====================================================*/
  94.  
  95. BOOL             QueryIni( HAB ) ;
  96. int              main( int, char** ) ;
  97. static HWND      InitHelp( HAB, HWND ) ;
  98.  
  99. /*==== c o d e ===============================================================*/
  100.  
  101. int main ( int argc, char **argv )
  102. /*
  103. ** args:  argv[1] : name to be used for IPC (pipes/semaphores) with gnuplot 
  104. ** 
  105. ** Standard PM initialisation:
  106. ** -- set up message processing loop
  107. ** -- register all window classes
  108. ** -- start up main window
  109. ** -- subclass main window for help and dde message trapping to frame window
  110. ** -- init help system
  111. ** -- check command line and open any filename found there
  112. **
  113. */
  114.     {
  115.     static ULONG flFrameFlags = (FCF_ACCELTABLE|FCF_STANDARD);//&(~FCF_TASKLIST) ;
  116.     static ULONG flClientFlags = WS_VISIBLE ;
  117.     HMQ          hmq ;
  118.     QMSG         qmsg ;
  119.     PFNWP        pfnOldFrameWndProc ;
  120.     HWND         hwndHelp ;        
  121.     BOOL         bPos ;
  122.  
  123.     /* (am, 19981001)
  124.      * A subtile problem is fixed here:
  125.      * upon the first initialization of this driver (i.e. we're here in main())
  126.      * it may inherit handles of files opened (temporarily) by gnuplot itself!
  127.      * We close them here.
  128.      */
  129.     fcloseall();
  130.  
  131.     if( argc <= 1 ) strcpy( szIPCName, IPCDEFAULT ) ;
  132.     else {
  133.         int i ;
  134.         strcpy( szIPCName, argv[1] ) ;
  135.         for ( i=2; i<argc; i++ ) {
  136.                     while( *argv[i] != '\0' ) {
  137.                 if( *argv[i] == '-' ) {
  138.                     ++argv[i] ;
  139.                     switch( *argv[i] ) {
  140.                         case 's' :
  141.                             bServer = 1 ;
  142.                             break ;
  143.                         case 'e' :
  144.                             bEnhanced = 1 ;
  145.                             break ;
  146.                         case 'p' :
  147.                             bPersist = 1 ;
  148.                             break ;
  149.                         case 'w' :
  150.                             bWideLines = 1 ;
  151.                             break ;
  152.                         }
  153.                     }
  154.                 else if ( *argv[i] == '"' ) {
  155.                     char *p = szTitle ;
  156.                     argv[i]++ ;
  157.                     while( *argv[i] != '"' ) {
  158.                         *p++ = *argv[i]++ ; 
  159.                         } 
  160.                     *p = '\0' ;
  161.                     }
  162.                 argv[i]++ ;
  163.                 }
  164.             } 
  165.         }
  166.     {
  167.     char *p ;
  168.         /* get path from argv[0] to track down program files */
  169.     strcpy( szIniFile, argv[0] ) ;
  170.     while( (p=strchr(szIniFile,'/'))!=NULL ) *p = '\\' ;
  171.     p = strrchr(szIniFile,'\\') ;
  172.     if(p==NULL) p = strrchr(szIniFile,':') ;    
  173.     if(p==NULL) p = szIniFile ;
  174.     else ++p ;
  175.     strcpy(p,GNUINI);
  176.     }
  177.     
  178.     hab = WinInitialize( 0 ) ;    
  179.     hmq = WinCreateMsgQueue( hab, 50 ) ;
  180.  
  181.                 // get defaults from gnupmdrv.ini
  182.  
  183.     bPos = QueryIni( hab ) ;
  184.                 
  185.                 // register window and child window classes
  186.  
  187.     if( ! WinRegisterClass( hab,        /* Exit if can't register */
  188.                             APP_NAME,
  189.                             (PFNWP)DisplayClientWndProc,
  190.                             CS_SIZEREDRAW,
  191.                             0 ) 
  192.                             ) return 0L ;
  193.  
  194.                 // create main window
  195.  
  196.     hwndFrame = WinCreateStdWindow (
  197.                     HWND_DESKTOP,
  198.                     0,//WS_VISIBLE,
  199.                     &flFrameFlags,
  200.                     APP_NAME,
  201.                     NULL,
  202.                     flClientFlags,
  203.                     0L,
  204.                     1,
  205.                     &hApp) ;
  206.  
  207.     if ( ! hwndFrame ) return 0 ;
  208.  
  209.                 // subclass window for help & DDE trapping
  210.  
  211.     pfnOldFrameWndProc = WinSubclassWindow( hwndFrame, (PFNWP)NewFrameWndProc ) ;
  212.     WinSetWindowULong( hwndFrame, QWL_USER, (ULONG) pfnOldFrameWndProc ) ;
  213.  
  214.                 // init the help manager
  215.  
  216.     hwndHelp = InitHelp( hab, hwndFrame ) ;        
  217.  
  218.                 // set window title and make it active
  219.  
  220.     {
  221.     char text[256] = APP_NAME;
  222.     strcat( text, " [" ) ;
  223.     strcat( text, szTitle ) ;
  224.     strcat( text, "]" ) ;
  225.     WinSetWindowText( hwndFrame, text ) ;
  226.     }
  227.                 // process window messages 
  228.       
  229.     while (WinGetMsg (hab, &qmsg, NULLHANDLE, 0, 0))
  230.          WinDispatchMsg (hab, &qmsg) ;
  231.  
  232.                 // shut down
  233.  
  234.     WinDestroyHelpInstance( hwndHelp ) ;
  235.     WinDestroyWindow (hwndFrame) ;
  236.     WinDestroyMsgQueue (hmq) ;
  237.     WinTerminate (hab) ;
  238.  
  239.     return 0 ;
  240.     }
  241.  
  242. static HWND InitHelp( HAB hab, HWND hwnd )
  243. /*
  244. **  initialise the help system
  245. */
  246.     {
  247.     static HELPINIT helpinit = { sizeof(HELPINIT),
  248.                                  0L,
  249.                                  NULL,
  250.                                  (PHELPTABLE)MAKELONG(1, 0xFFFF),
  251.                                  0L,
  252.                                  0L,
  253.                                  0,
  254.                                  0,
  255.                                  "GnuplotPM Help",
  256.                                  CMIC_HIDE_PANEL_ID,
  257.                                  "gnupmdrv.hlp" } ;
  258.     HWND hwndHelp ;
  259.     static char helppath[256] ;
  260.     char *p ;
  261.     if( (p=getenv("GNUPLOT")) != NULL ) {
  262.         strcpy( helppath, p ) ;
  263.         strcat( helppath, "/" ) ;
  264.         strcat( helppath, helpinit.pszHelpLibraryName ) ;
  265.         helpinit.pszHelpLibraryName = helppath ;
  266.         }    
  267.     hwndHelp = WinCreateHelpInstance( hab, &helpinit ) ;
  268.     WinAssociateHelpInstance( hwndHelp, hwnd ) ;
  269.     return hwndHelp ;
  270.     }
  271.  
  272. MRESULT EXPENTRY NewFrameWndProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  273. /*
  274. **  Subclasses top-level frame window to trap help & dde messages
  275. */
  276.     {
  277.     PFNWP       pfnOldFrameWndProc ;
  278.     
  279.     pfnOldFrameWndProc = (PFNWP) WinQueryWindowULong( hwnd, QWL_USER ) ; 
  280.     switch( msg ) {
  281.         default: 
  282.             break ;
  283.  
  284.         case HM_QUERY_KEYS_HELP:
  285.             return (MRESULT) IDH_KEYS ;            
  286.         }
  287.     return (*pfnOldFrameWndProc)(hwnd, msg, mp1, mp2) ;    
  288.     }
  289.  
  290.  
  291. MRESULT EXPENTRY About( HWND hDlg, ULONG message, MPARAM mp1, MPARAM mp2)
  292. /*
  293. ** 'About' box dialog function
  294. */
  295.     {
  296.     return WinDefDlgProc( hDlg, message, mp1, mp2 ) ;
  297.     }
  298.  
  299.